Q1: What is the trend in cases, mortality across geopgraphical regions?
Plot # of cases vs time
* For each geographical set:
* comparative longitudinal case trend (absolute & log scale)
* comparative longitudinal mortality trend
* death vs total correlation
| comparative_longitudinal_case_trend |
long |
time |
log_cases |
geography |
none (case type?) |
case_type |
[15, 50, 4] geography x (2 scale?) case type |
| comparative longitudinal case trend |
long |
time |
cases |
geography |
case_type |
? |
[15, 50, 4] geography x (2+ scale) case type |
| comparative longitudinal mortality trend |
wide |
time |
mortality rate |
geography |
none |
none |
[15, 50, 4] geography |
| death vs total correlation |
wide |
cases |
deaths |
geography |
none |
none |
[15, 50, 4] geography |
# total cases vs time
# death cases vs time
# mortality rate vs time
# death vs mortality
# death vs mortality
# total & death case vs time (same plot)
#<question> <x> <y> <colored> <facet> <dataset>
## trend in case/deaths over time, comapred across regions <time> <log cases> <geography*> <none> <.wide>
## trend in case/deaths over time, comapred across regions <time> <cases> <geography*> <case_type> <.long>
## trend in mortality rate over time, comapred across regions <time> <mortality rate> <geography*> <none>
## how are death/mortality related/correlated? <time> <log cases> <geography*> <none>
## how are death and case load correlated? <cases> <deaths>
# lm for each?? - > apply lm from each region starting from 100th case. m, b associated with each.
# input: geographical regsion, logcase vs day (100th case)
# output: m, b for each geographical region ID
#total/death on same plot- diffeer by 2 logs, so when plotting log, use pch. when plotting absolute, need to use free scales
#when plotting death and case on same, melt.
#CoronaCases - > filter sets (3)
#world - choose countries with sufficent data
N<-ddply(filter(Corona_Cases,Total_confirmed_cases>100),c("Country.Region"),summarise,n=length(Country.Region))
ggplot(filter(N,n<100),aes(x=n))+
geom_histogram()+
default_theme+
ggtitle("Distribution of number of days with at least 100 confirmed cases for each region")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

kable(arrange(N,-n),caption="Sorted number of days with at least 100 confirmed cases")
Sorted number of days with at least 100 confirmed cases
| US_state |
78436 |
| China |
159 |
| Diamond Princess |
140 |
| Korea, South |
130 |
| Japan |
129 |
| Italy |
127 |
| Iran |
124 |
| Singapore |
121 |
| France |
120 |
| Germany |
120 |
| Spain |
119 |
| US |
117 |
| Switzerland |
116 |
| United Kingdom |
116 |
| Belgium |
115 |
| Netherlands |
115 |
| Norway |
115 |
| Sweden |
115 |
| Austria |
113 |
| Malaysia |
112 |
| Australia |
111 |
| Bahrain |
111 |
| Denmark |
111 |
| Canada |
110 |
| Qatar |
110 |
| Iceland |
109 |
| Brazil |
108 |
| Czechia |
108 |
| Finland |
108 |
| Greece |
108 |
| Iraq |
108 |
| Israel |
108 |
| Portugal |
108 |
| Slovenia |
108 |
| Egypt |
107 |
| Estonia |
107 |
| India |
107 |
| Ireland |
107 |
| Kuwait |
107 |
| Philippines |
107 |
| Poland |
107 |
| Romania |
107 |
| Saudi Arabia |
107 |
| Indonesia |
106 |
| Lebanon |
106 |
| Pakistan |
106 |
| San Marino |
106 |
| Thailand |
106 |
| Chile |
105 |
| Luxembourg |
104 |
| Peru |
104 |
| Russia |
104 |
| Ecuador |
103 |
| Mexico |
103 |
| Slovakia |
103 |
| South Africa |
103 |
| United Arab Emirates |
103 |
| Armenia |
102 |
| Colombia |
102 |
| Croatia |
102 |
| Panama |
102 |
| Serbia |
102 |
| Taiwan* |
102 |
| Turkey |
102 |
| Argentina |
101 |
| Bulgaria |
101 |
| Latvia |
101 |
| Uruguay |
101 |
| Algeria |
100 |
| Costa Rica |
100 |
| Dominican Republic |
100 |
| Hungary |
100 |
| Andorra |
99 |
| Bosnia and Herzegovina |
99 |
| Jordan |
99 |
| Lithuania |
99 |
| Morocco |
99 |
| New Zealand |
99 |
| North Macedonia |
99 |
| Vietnam |
99 |
| Albania |
98 |
| Cyprus |
98 |
| Malta |
98 |
| Moldova |
98 |
| Brunei |
97 |
| Burkina Faso |
97 |
| Sri Lanka |
97 |
| Tunisia |
97 |
| Ukraine |
96 |
| Azerbaijan |
95 |
| Ghana |
95 |
| Kazakhstan |
95 |
| Oman |
95 |
| Senegal |
95 |
| Venezuela |
95 |
| Afghanistan |
94 |
| Cote d’Ivoire |
94 |
| Cuba |
93 |
| Mauritius |
93 |
| Uzbekistan |
93 |
| Cambodia |
92 |
| Cameroon |
92 |
| Honduras |
92 |
| Nigeria |
92 |
| West Bank and Gaza |
92 |
| Belarus |
91 |
| Georgia |
91 |
| Bolivia |
90 |
| Kosovo |
90 |
| Kyrgyzstan |
90 |
| Montenegro |
90 |
| Congo (Kinshasa) |
89 |
| Kenya |
88 |
| Niger |
87 |
| Guinea |
86 |
| Rwanda |
86 |
| Trinidad and Tobago |
86 |
| Paraguay |
85 |
| Bangladesh |
84 |
| Djibouti |
82 |
| El Salvador |
81 |
| Guatemala |
80 |
| Madagascar |
79 |
| Mali |
78 |
| Congo (Brazzaville) |
75 |
| Jamaica |
75 |
| Gabon |
73 |
| Somalia |
73 |
| Tanzania |
73 |
| Ethiopia |
72 |
| Burma |
71 |
| Sudan |
70 |
| Liberia |
69 |
| Maldives |
67 |
| Equatorial Guinea |
66 |
| Cabo Verde |
64 |
| Sierra Leone |
62 |
| Guinea-Bissau |
61 |
| Togo |
61 |
| Zambia |
60 |
| Eswatini |
59 |
| Chad |
58 |
| Tajikistan |
57 |
| Haiti |
55 |
| Sao Tome and Principe |
55 |
| Benin |
53 |
| Nepal |
53 |
| Uganda |
53 |
| Central African Republic |
52 |
| South Sudan |
52 |
| Guyana |
50 |
| Mozambique |
49 |
| Yemen |
45 |
| Mongolia |
44 |
| Mauritania |
41 |
| Nicaragua |
41 |
| Malawi |
35 |
| Syria |
35 |
| Zimbabwe |
33 |
| Bahamas |
32 |
| Libya |
32 |
| Comoros |
30 |
| Suriname |
22 |
| Angola |
19 |
| Eritrea |
14 |
| Burundi |
13 |
| Monaco |
7 |
| Namibia |
4 |
# Pick top 15 countries with data
max_colors<-12
# find way to fix this- China has diff provences. Plot doesnt look right...
sufficient_data<-arrange(filter(N,!Country.Region %in% c("US_state", "Diamond Princess")),-n)[1:max_colors,]
kable(sufficient_data,caption = paste0("Top ",max_colors," countries with sufficient data"))
Top 12 countries with sufficient data
| China |
159 |
| Korea, South |
130 |
| Japan |
129 |
| Italy |
127 |
| Iran |
124 |
| Singapore |
121 |
| France |
120 |
| Germany |
120 |
| Spain |
119 |
| US |
117 |
| Switzerland |
116 |
| United Kingdom |
116 |
Corona_Cases.world<-filter(Corona_Cases,Country.Region %in% c(sufficient_data$Country.Region))
#us
# - by state
Corona_Cases.US<-filter(Corona_Cases,Country.Region=="US" & Total_confirmed_cases>0)
# summarize
#!City %in% c("Unassigned")
# - specific cities
#mortality_rate!=Inf & mortality_rate<=1
head(Corona_Cases)
## Country.Region Province.State City Date Date.numeric
## 1 Afghanistan <NA> <NA> 2020-02-07 18299
## 2 Afghanistan <NA> <NA> 2020-04-13 18365
## 3 Afghanistan <NA> <NA> 2020-02-08 18300
## 4 Afghanistan <NA> <NA> 2020-06-05 18418
## 5 Afghanistan <NA> <NA> 2020-06-04 18417
## 6 Afghanistan <NA> <NA> 2020-02-06 18298
## Total_confirmed_deaths Total_confirmed_cases mortality_rate
## 1 0 0 NaN
## 2 21 665 0.03157895
## 3 0 0 NaN
## 4 309 18969 0.01628974
## 5 300 18054 0.01661682
## 6 0 0 NaN
## Total_confirmed_cases.log Total_confirmed_deaths.log case100_date
## 1 -Inf -Inf 18348
## 2 2.822822 1.322219 18348
## 3 -Inf -Inf 18348
## 4 4.278044 2.489958 18348
## 5 4.256573 2.477121 18348
## 6 -Inf -Inf 18348
## Days_since_100 Lat Long Population Total_confirmed_cases.per100
## 1 -49 NA NA NA NA
## 2 17 NA NA NA NA
## 3 -48 NA NA NA NA
## 4 70 NA NA NA NA
## 5 69 NA NA NA NA
## 6 -50 NA NA NA NA
## Total_confirmed_deaths.per100
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
Corona_Cases[!is.na(Corona_Cases$Province.State) & Corona_Cases$Province.State=="Pennsylvania" & Corona_Cases$City=="Delaware","City"]<-"Delaware_PA"
Corona_Cases.UScity<-filter(Corona_Cases,Province.State %in% c("Pennsylvania","Maryland","New York","New Jersey") & City %in% c("Bucks","Baltimore City", "New York","Burlington","Cape May","Delaware_PA"))
measure_vars_long<-c("Total_confirmed_cases.log","Total_confirmed_cases","Total_confirmed_deaths","Total_confirmed_deaths.log")
melt_arg_list<-list(variable.name = "case_type",value.name = "cases",measure.vars = c("Total_confirmed_cases","Total_confirmed_deaths"))
melt_arg_list$data=NULL
melt_arg_list$data=select(Corona_Cases.world,-ends_with(match = "log"))
Corona_Cases.world.long<-do.call(melt,melt_arg_list)
melt_arg_list$data=select(Corona_Cases.UScity,-ends_with(match = "log"))
Corona_Cases.UScity.long<-do.call(melt,melt_arg_list)
melt_arg_list$data=select(Corona_Cases.US_state,-ends_with(match = "log"))
Corona_Cases.US_state.long<-do.call(melt,melt_arg_list)
Corona_Cases.world.long$cases.log<-log(Corona_Cases.world.long$cases,10)
Corona_Cases.US_state.long$cases.log<-log(Corona_Cases.US_state.long$cases,10)
Corona_Cases.UScity.long$cases.log<-log(Corona_Cases.UScity.long$cases,10)
# what is the current death and total case load for US? For world? For states?
#-absolute
#-log
# what is mortality rate (US, world)
#-absolute
#how is death and case correlated? (US, world)
#-absolute
#Corona_Cases.US<-filter(Corona_Cases,Country.Region=="US" & Total_confirmed_cases>0)
#Corona_Cases.US.case100<-filter(Corona_Cases.US, Days_since_100>=0)
# linear model parameters
#(model_fit<-lm(formula = Total_confirmed_cases.log~Days_since_100,data= Corona_Cases.US.case100 ))
#(slope<-model_fit$coefficients[2])
#(intercept<-model_fit$coefficients[1])
# Correlation coefficient
#cor(x = Corona_Cases.US.case100$Days_since_100,y = Corona_Cases.US.case100$Total_confirmed_cases.log)
##------------------------------------------
## Plot World Data
##------------------------------------------
# Timestamp for world
timestamp_plot.world<-paste("Most recent date for which data available:",max(Corona_Cases.world$Date))#timestamp(quiet = T,prefix = "Updated ",suffix = " (EST)")
# Base template for plots
baseplot.world<-ggplot(data=NULL,aes(x=Days_since_100,col=Country.Region))+
default_theme+
scale_color_brewer(type = "qualitative",palette = "Paired")+
ggtitle(paste("Log10 cases over time,",timestamp_plot.world))+
theme(legend.position = "bottom",plot.title = element_text(size=12))
##/////////////////////////
### Plot Longitudinal cases
(Corona_Cases.world.long.plot<-baseplot.world+
geom_point(data=Corona_Cases.world.long,aes(y=cases))+
geom_line(data=Corona_Cases.world.long,aes(y=cases))+
facet_wrap(~case_type,scales = "free_y",ncol=1)+
ggtitle(timestamp_plot.world)
)

(Corona_Cases.world.loglong.plot<-baseplot.world+
geom_point(data=Corona_Cases.world.long,aes(y=cases.log))+
geom_line(data=Corona_Cases.world.long,aes(y=cases.log))+
facet_wrap(~case_type,scales = "free_y",ncol=1)+
ggtitle(timestamp_plot.world))

##/////////////////////////
### Plot Longitudinal mortality rate
(Corona_Cases.world.mortality.plot<-baseplot.world+
geom_point(data=Corona_Cases.world,aes(y=mortality_rate))+
geom_line(data=Corona_Cases.world,aes(y=mortality_rate))+
ylim(c(0,0.3))+
ggtitle(timestamp_plot.world))
## Warning: Removed 100 rows containing missing values (geom_point).
## Warning: Removed 100 row(s) containing missing values (geom_path).

##/////////////////////////
### Plot death vs total case correlation
(Corona_Cases.world.casecor.plot<-ggplot(Corona_Cases.world,aes(x=Total_confirmed_cases,y=Total_confirmed_deaths,col=Country.Region))+
geom_point()+
geom_line()+
default_theme+
scale_color_brewer(type = "qualitative",palette = "Paired")+
ggtitle(paste("Log10 cases over time,",timestamp_plot.world))+
theme(legend.position = "bottom",plot.title = element_text(size=12))+
ggtitle(timestamp_plot.world))

### Write polots
write_plot(Corona_Cases.world.long.plot,wd = results_dir)
## [1] "/Users/stevensmith/Projects/coronavirus/results/Corona_Cases.world.long.plot.png"
write_plot(Corona_Cases.world.loglong.plot,wd = results_dir)
## [1] "/Users/stevensmith/Projects/coronavirus/results/Corona_Cases.world.loglong.plot.png"
write_plot(Corona_Cases.world.mortality.plot,wd = results_dir)
## Warning: Removed 100 rows containing missing values (geom_point).
## Warning: Removed 100 row(s) containing missing values (geom_path).
## [1] "/Users/stevensmith/Projects/coronavirus/results/Corona_Cases.world.mortality.plot.png"
write_plot(Corona_Cases.world.casecor.plot,wd = results_dir)
## [1] "/Users/stevensmith/Projects/coronavirus/results/Corona_Cases.world.casecor.plot.png"
##------------------------------------------
## Plot US State Data
##-----------------------------------------
baseplot.US<-ggplot(data=NULL,aes(x=Days_since_100_state,col=case_type))+
default_theme+
facet_wrap(~Province.State)+
ggtitle(paste("Log10 cases over time,",timestamp_plot.world))
Corona_Cases.US_state.long.plot<-baseplot.US+geom_point(data=Corona_Cases.US_state.long,aes(y=cases.log))
##------------------------------------------
## Plot US City Data
##-----------------------------------------
Corona_Cases.US.plotdata<-filter(Corona_Cases.US_state,Province.State %in% c("Pennsylvania","Maryland","New York","New Jersey") &
City %in% c("Bucks","Baltimore City", "New York","Burlington","Cape May","Delaware_PA") &
Total_confirmed_cases>0)
timestamp_plot<-paste("Most recent date for which data available:",max(Corona_Cases.US.plotdata$Date))#timestamp(quiet = T,prefix = "Updated ",suffix = " (EST)")
city_colors<-c("Bucks"='#beaed4',"Baltimore City"='#386cb0', "New York"='#7fc97f',"Burlington"='#fdc086',"Cape May"="#e78ac3","Delaware_PA"="#b15928")
##/////////////////////////
### Plot death vs total case correlation
(Corona_Cases.city.loglong.plot<-ggplot(melt(Corona_Cases.US.plotdata,measure.vars = c("Total_confirmed_cases.log","Total_confirmed_deaths.log"),variable.name = "case_type",value.name = "cases"),aes(x=Date,y=cases,col=City,pch=case_type))+
geom_point(size=4)+
geom_line()+
default_theme+
#facet_wrap(~case_type)+
ggtitle(paste("Log10 total and death cases over time,",timestamp_plot))+
theme(legend.position = "bottom",plot.title = element_text(size=12),axis.text.x = element_text(angle=45,hjust=1))+
scale_color_manual(values = city_colors)+
scale_x_date(date_breaks="1 week",date_minor_breaks="1 day"))

(Corona_Cases.city.long.plot<-ggplot(filter(Corona_Cases.US.plotdata,Province.State !="New York"),aes(x=Date,y=Total_confirmed_cases,col=City))+
geom_point(size=4)+
geom_line()+
default_theme+
facet_grid(~Province.State,scales = "free_y")+
ggtitle(paste("MD, PA, NJ total cases over time,",timestamp_plot))+
theme(legend.position = "bottom",plot.title = element_text(size=12),axis.text.x = element_text(angle=45,hjust=1))
+
scale_color_manual(values = city_colors)+
scale_x_date(date_breaks="1 week",date_minor_breaks="1 day"))

(Corona_Cases.city.mortality.plot<-ggplot(Corona_Cases.US.plotdata,aes(x=Date,y=mortality_rate,col=City))+
geom_point(size=3)+
geom_line(size=2)+
default_theme+
ggtitle(paste("Mortality rate (deaths/total) over time,",timestamp_plot))+
theme(legend.position = "bottom",plot.title = element_text(size=12),axis.text.x = element_text(angle=45,hjust=1))+
scale_color_manual(values = city_colors)+
scale_x_date(date_breaks="1 week",date_minor_breaks="1 day"))

(Corona_Cases.city.casecor.plot<-ggplot(filter(Corona_Cases.US.plotdata,Province.State !="New York"),aes(y=Total_confirmed_deaths,x=Total_confirmed_cases,col=City))+
geom_point(size=3)+
geom_line(size=2)+
default_theme+
ggtitle(paste("Correlation of death vs total cases,",timestamp_plot))+
theme(legend.position = "bottom",plot.title = element_text(size=12))+
scale_color_manual(values = city_colors))

(Corona_Cases.city.long.normalized.plot<-ggplot(filter(Corona_Cases.US.plotdata,Province.State !="New York"),aes(x=Date,y=Total_confirmed_cases.per100,col=City))+
geom_point(size=4)+
geom_line()+
default_theme+
facet_grid(~Province.State)+
ggtitle(paste("MD, PA, NJ total cases over time per 100 people,",timestamp_plot))+
theme(legend.position = "bottom",plot.title = element_text(size=12),axis.text.x = element_text(angle=45,hjust=1))+
scale_color_manual(values = city_colors) +
scale_x_date(date_breaks="1 week",date_minor_breaks="1 day"))

write_plot(Corona_Cases.city.long.plot,wd = results_dir_custom)
## [1] "/Users/stevensmith/Projects/coronavirus/results/custom/Corona_Cases.city.long.plot.png"
write_plot(Corona_Cases.city.loglong.plot,wd = results_dir_custom)
## [1] "/Users/stevensmith/Projects/coronavirus/results/custom/Corona_Cases.city.loglong.plot.png"
write_plot(Corona_Cases.city.mortality.plot,wd = results_dir_custom)
## [1] "/Users/stevensmith/Projects/coronavirus/results/custom/Corona_Cases.city.mortality.plot.png"
write_plot(Corona_Cases.city.casecor.plot,wd = results_dir_custom)
## [1] "/Users/stevensmith/Projects/coronavirus/results/custom/Corona_Cases.city.casecor.plot.png"
write_plot(Corona_Cases.city.long.normalized.plot,wd = results_dir_custom)
## [1] "/Users/stevensmith/Projects/coronavirus/results/custom/Corona_Cases.city.long.normalized.plot.png"
Q1b what is the model
Fit the cases to a linear model 1. Find time at which the case vs date becomes linear in each plot
2. Fit linear model for each city
# What is the predict # of cases for the next few days?
# How is the model performing historically?
Corona_Cases.US_state.summary<-ddply(Corona_Cases.US_state,
c("Province.State","Date"),
summarise,
Total_confirmed_cases_perstate=sum(Total_confirmed_cases)) %>%
filter(Total_confirmed_cases_perstate>100)
# Compute the states with the most cases (for coloring and for linear model)
top_states_totals<-head(ddply(Corona_Cases.US_state.summary,c("Province.State"),summarise, Total_confirmed_cases_perstate.max=max(Total_confirmed_cases_perstate)) %>% arrange(-Total_confirmed_cases_perstate.max),n=max_colors)
kable(top_states_totals,caption = "Top 12 States, total count ")
top_states<-top_states_totals$Province.State
# Manually fix states so that Maryland is switched out for New York
top_states_modified<-c(top_states[top_states !="New York"],"Maryland")
# Plot with all states:
(Corona_Cases.US_state.summary.plot<-ggplot(Corona_Cases.US_state.summary,aes(x=Date,y=Total_confirmed_cases_perstate))+
geom_point()+
geom_point(data=filter(Corona_Cases.US_state.summary,Province.State %in% top_states),aes(col=Province.State))+
scale_color_brewer(type = "qualitative",palette = "Paired")+
default_theme+
theme(axis.text.x = element_text(angle=45,hjust=1),legend.position = "bottom")+
ggtitle("Total confirmed cases per state, top 12 colored")+
scale_x_date(date_breaks="1 week",date_minor_breaks="1 day"))
##------------------------------------------
## Fit linear model to time vs total cases
##-----------------------------------------
# First, find the date at which each state's cases vs time becomes lienar (2nd derivative is about 0)
li<-ddply(Corona_Cases.US_state.summary,c("Province.State"),find_linear_index)
# Compute linear model for each state starting at the point at which data becomes linear
for(i in 1:nrow(li)){
Province.State.i<-li[i,"Province.State"]
date.i<-li[i,"V1"]
data.i<-filter(Corona_Cases.US_state.summary,Province.State==Province.State.i & as.numeric(Date) >= date.i)
model_results<-lm(data.i,formula = Total_confirmed_cases_perstate~Date)
slope<-model_results$coefficients[2]
intercept<-model_results$coefficients[1]
li[li$Province.State==Province.State.i,"m"]<-slope
li[li$Province.State==Province.State.i,"b"]<-intercept
}
# Compute top state case load with fitted model
(Corona_Cases.US_state.lm.plot<-ggplot(filter(Corona_Cases.US_state.summary,Province.State %in% top_states_modified ))+
geom_abline(data=filter(li,Province.State %in% top_states_modified),
aes(slope = m,intercept = b,col=Province.State),lty=2)+
geom_point(aes(x=Date,y=Total_confirmed_cases_perstate,col=Province.State))+
scale_color_brewer(type = "qualitative",palette = "Paired")+
default_theme+
theme(axis.text.x = element_text(angle=45,hjust=1),legend.position = "bottom")+
ggtitle("Total confirmed cases per state, top 12 colored")+
scale_x_date(date_breaks="1 week",date_minor_breaks="1 day"))
##------------------------------------------
## Predict the number of total cases over the next week
##-----------------------------------------
predicted_days<-c(0,1,2,3,7)+as.numeric(as.Date("2020-04-20"))
predicted_days_df<-data.frame(matrix(ncol=3))
names(predicted_days_df)<-c("Province.State","days","Total_confirmed_cases_perstate")
# USe model parameters to estiamte case loads
for(state.i in top_states_modified){
predicted_days_df<-rbind(predicted_days_df,
data.frame(Province.State=state.i,
prediction_model(m = li[li$Province.State==state.i,"m"],
b =li[li$Province.State==state.i,"b"] ,
days =predicted_days )))
}
predicted_days_df$Date<-as.Date(predicted_days_df$days,origin="1970-01-01")
kable(predicted_days_df,caption = "Predicted total cases over the next week for selected states")
##------------------------------------------
## Write plots
##-----------------------------------------
write_plot(Corona_Cases.US_state.summary.plot,wd = results_dir)
write_plot(Corona_Cases.US_state.lm.plot,wd = results_dir)
##------------------------------------------
## Write tables
##-----------------------------------------
write.csv(predicted_days_df,file = paste0(results_dir,"predicted_total_cases_days.csv"),quote = F,row.names = F)
Q2: What is the predicted number of cases?
What is the prediction of COVID-19 based on model thus far? Additional questions:
WHy did it take to day 40 to start a log linear trend? How long will it be till x number of cases? When will the plateu happen? Are any effects noticed with social distancing? Delays
##------------------------------------------
## Prediction and Prediction Accuracy
##------------------------------------------
today_num<-max(Corona_Cases.US$Days_since_100)
predicted_days<-today_num+c(1,2,3,7)
#mods = dlply(mydf, .(x3), lm, formula = y ~ x1 + x2)
#today:
Corona_Cases.US[Corona_Cases.US$Days_since_100==(today_num-1),]
Corona_Cases.US[Corona_Cases.US$Days_since_100==today_num,]
Corona_Cases.US$type<-"Historical"
#prediction_values<-prediction_model(m=slope,b=intercept,days = predicted_days)$Total_confirmed_cases
histoical_model<-data.frame(date=today_num,m=slope,b=intercept)
tmp<-data.frame(state=rep(c("A","B"),each=3),x=c(1,2,3,4,5,6))
tmp$y<-c(tmp[1:3,"x"]+5,tmp[4:6,"x"]*5+1)
ddply(tmp,c("state"))
lm(data =tmp,formula = y~x )
train_lm<-function(input_data,subset_coulmn,formula_input){
case_models <- dlply(input_data, subset_coulmn, lm, formula = formula_input)
case_models.parameters <- ldply(case_models, coef)
case_models.parameters<-rename(case_models.parameters,c("b"="(Intercept)","m"=subset_coulmn))
return(case_models.parameters)
}
train_lm(tmp,"state")
dlply(input_data, subset_coulmn, lm,m=)
# model for previous y days
#historical_model_predictions<-data.frame(day_x=NULL,Days_since_100=NULL,Total_confirmed_cases=NULL,Total_confirmed_cases.log=NULL)
# for(i in c(1,2,3,4,5,6,7,8,9,10)){
# #i<-1
# day_x<-today_num-i # 1, 2, 3, 4
# day_x_nextweek<-day_x+c(1,2,3)
# model_fit_x<-lm(data = filter(Corona_Cases.US.case100,Days_since_100 < day_x),formula = Total_confirmed_cases.log~Days_since_100)
# prediction_day_x_nextweek<-prediction_model(m = model_fit_x$coefficients[2],b = model_fit_x$coefficients[1],days = day_x_nextweek)
# prediction_day_x_nextweek$type<-"Predicted"
# acutal_day_x_nextweek<-filter(Corona_Cases.US,Days_since_100 %in% day_x_nextweek) %>% select(c(Days_since_100,Total_confirmed_cases,Total_confirmed_cases.log))
# acutal_day_x_nextweek$type<-"Historical"
# historical_model_predictions.i<-data.frame(day_x=day_x,rbind(acutal_day_x_nextweek,prediction_day_x_nextweek))
# historical_model_predictions<-rbind(historical_model_predictions.i,historical_model_predictions)
# }
#historical_model_predictions.withHx<-rbind.fill(historical_model_predictions,data.frame(Corona_Cases.US,type="Historical"))
#historical_model_predictions.withHx$Total_confirmed_cases.log2<-log(historical_model_predictions.withHx$Total_confirmed_cases,2)
(historical_model_predictions.plot<-ggplot(historical_model_predictions.withHx,aes(x=Days_since_100,y=Total_confirmed_cases.log,col=type))+
geom_point(size=3)+
default_theme+
theme(legend.position = "bottom")+
#geom_abline(slope = slope,intercept =intercept,lty=2)+
#facet_wrap(~case_type,ncol=1)+
scale_color_manual(values = c("Historical"="#377eb8","Predicted"="#e41a1c")))
write_plot(historical_model_predictions.plot,wd=results_dir)
Q3: What is the effect on social distancing, descreased mobility on case load?
Load data from Google which compoutes % change in user mobility relative to baseline for * Recreation
* Workplace
* Residence
* Park
* Grocery
Data from https://www.google.com/covid19/mobility/
# See pre-processing section for script on gathering mobility data
# UNDER DEVELOPMENT
mobility<-read.csv("/Users/stevensmith/Projects/MIT_COVID19/mobility.csv",header = T,stringsAsFactors = F)
#mobility$Retail_Recreation<-as.numeric(sub(mobility$Retail_Recreation,pattern = "%",replacement = ""))
#mobility$Workplace<-as.numeric(sub(mobility$Workplace,pattern = "%",replacement = ""))
#mobility$Residential<-as.numeric(sub(mobility$Residential,pattern = "%",replacement = ""))
##------------------------------------------
## Show relationship between mobility and caseload
##------------------------------------------
mobility$County<-gsub(mobility$County,pattern = " County",replacement = "")
Corona_Cases.US_state.mobility<-merge(Corona_Cases.US_state,plyr::rename(mobility,c("State"="Province.State","County"="City")))
#Corona_Cases.US_state.tmp<-merge(metadata,Corona_Cases.US_state.tmp)
# Needs to happen upsteam, see todos
#Corona_Cases.US_state.tmp$Total_confirmed_cases.perperson<-Corona_Cases.US_state.tmp$Total_confirmed_cases/as.numeric(Corona_Cases.US_state.tmp$Population)
mobility_measures<-c("Retail_Recreation","Grocery_Pharmacy","Parks","Transit","Workplace","Residential")
plot_data<-filter(Corona_Cases.US_state.mobility, Date.numeric==max(Corona_Cases.US_state$Date.numeric) ) %>% melt(measure.vars=mobility_measures)
plot_data$value<-as.numeric(gsub(plot_data$value,pattern = "%",replacement = ""))
plot_data<-filter(plot_data,!is.na(value))
(mobility.plot<-ggplot(filter(plot_data,Province.State %in% c("Pennsylvania","Maryland","New Jersey","California","Delaware","Connecticut")),aes(y=Total_confirmed_cases.per100,x=value))+geom_point()+
facet_grid(Province.State~variable,scales = "free")+
xlab("Mobility change from baseline (%)")+
ylab(paste0("Confirmed cases per 100 people(Today)"))+
default_theme+
ggtitle("Mobility change vs cases"))

(mobility.global.plot<-ggplot(plot_data,aes(y=Total_confirmed_cases.per100,x=value))+geom_point()+
facet_wrap(~variable,scales = "free")+
xlab("Mobility change from baseline (%)")+
ylab(paste0("Confirmed cases (Today) per 100 people"))+
default_theme+
ggtitle("Mobility change vs cases"))

plot_data.permobility_summary<-ddply(plot_data,c("Province.State","variable"),summarise,cor=cor(y =Total_confirmed_cases.per100,x=value),median_change=median(x=value)) %>% arrange(-abs(cor))
kable(plot_data.permobility_summary,caption = "Ranked per-state mobility correlation with total confirmed cases")
Ranked per-state mobility correlation with total confirmed cases
| Alaska |
Transit |
1.0000000 |
-63.0 |
| Delaware |
Retail_Recreation |
1.0000000 |
-39.5 |
| Delaware |
Grocery_Pharmacy |
1.0000000 |
-17.5 |
| Delaware |
Parks |
-1.0000000 |
20.5 |
| Delaware |
Transit |
1.0000000 |
-37.0 |
| Delaware |
Workplace |
1.0000000 |
-37.0 |
| Delaware |
Residential |
-1.0000000 |
14.0 |
| New Hampshire |
Parks |
0.9477267 |
-20.0 |
| Hawaii |
Transit |
0.9337007 |
-89.0 |
| Vermont |
Parks |
0.9245249 |
-35.5 |
| Maine |
Transit |
-0.9197347 |
-50.0 |
| Hawaii |
Parks |
0.9011090 |
-72.0 |
| Connecticut |
Grocery_Pharmacy |
-0.8815014 |
-6.0 |
| Utah |
Transit |
-0.8584685 |
-18.0 |
| Utah |
Residential |
-0.8298114 |
12.0 |
| South Dakota |
Parks |
0.7868708 |
-26.0 |
| Rhode Island |
Workplace |
-0.7691260 |
-39.5 |
| Arizona |
Residential |
0.7670081 |
13.0 |
| Arizona |
Grocery_Pharmacy |
-0.7597987 |
-15.0 |
| Connecticut |
Transit |
-0.7521408 |
-50.0 |
| Massachusetts |
Workplace |
-0.7494943 |
-39.0 |
| Alaska |
Residential |
0.7461094 |
13.0 |
| Nevada |
Transit |
-0.7340523 |
-20.0 |
| Alaska |
Workplace |
-0.7164857 |
-33.0 |
| Idaho |
Residential |
-0.7102565 |
11.0 |
| Wyoming |
Parks |
-0.6773507 |
-4.0 |
| North Dakota |
Parks |
0.6591628 |
-34.0 |
| New York |
Workplace |
-0.6546234 |
-34.5 |
| Hawaii |
Workplace |
-0.6439550 |
-46.0 |
| Vermont |
Grocery_Pharmacy |
-0.6289682 |
-25.0 |
| Rhode Island |
Retail_Recreation |
-0.6280705 |
-45.0 |
| Arkansas |
Parks |
0.6097123 |
-12.0 |
| Rhode Island |
Residential |
-0.5981837 |
18.5 |
| New Jersey |
Parks |
-0.5935765 |
-6.0 |
| New York |
Retail_Recreation |
-0.5912506 |
-46.0 |
| Maine |
Workplace |
-0.5871386 |
-30.0 |
| Utah |
Parks |
-0.5868620 |
17.0 |
| Nebraska |
Workplace |
0.5763620 |
-32.0 |
| Alaska |
Grocery_Pharmacy |
-0.5519294 |
-7.0 |
| New York |
Parks |
0.5307795 |
20.0 |
| Hawaii |
Grocery_Pharmacy |
0.5214587 |
-34.0 |
| Connecticut |
Retail_Recreation |
-0.5174922 |
-45.0 |
| New Jersey |
Workplace |
-0.5169103 |
-44.0 |
| Maine |
Parks |
0.5161871 |
-31.0 |
| Utah |
Workplace |
-0.5129174 |
-37.0 |
| Connecticut |
Residential |
0.5069468 |
14.0 |
| Massachusetts |
Retail_Recreation |
-0.4929561 |
-44.0 |
| New Mexico |
Grocery_Pharmacy |
-0.4843827 |
-11.0 |
| Arizona |
Retail_Recreation |
-0.4835134 |
-42.5 |
| South Carolina |
Parks |
-0.4803608 |
-23.0 |
| New Jersey |
Grocery_Pharmacy |
-0.4784647 |
2.5 |
| Connecticut |
Workplace |
-0.4698748 |
-39.0 |
| Nebraska |
Residential |
-0.4659245 |
14.0 |
| Arizona |
Transit |
0.4658453 |
-38.0 |
| New Mexico |
Residential |
0.4623380 |
13.5 |
| Maryland |
Workplace |
-0.4580481 |
-35.0 |
| Rhode Island |
Parks |
0.4463111 |
52.0 |
| Iowa |
Parks |
-0.4382099 |
28.5 |
| West Virginia |
Parks |
0.4336659 |
-33.0 |
| Kentucky |
Parks |
-0.4309633 |
28.5 |
| Missouri |
Residential |
-0.4301443 |
13.0 |
| Pennsylvania |
Workplace |
-0.4226384 |
-36.0 |
| North Dakota |
Retail_Recreation |
-0.4217110 |
-42.0 |
| Vermont |
Residential |
0.4198163 |
11.5 |
| Illinois |
Transit |
-0.4137696 |
-31.0 |
| Maryland |
Grocery_Pharmacy |
-0.4091531 |
-10.0 |
| New Jersey |
Retail_Recreation |
-0.4079658 |
-62.5 |
| Hawaii |
Retail_Recreation |
0.4057813 |
-56.0 |
| Massachusetts |
Grocery_Pharmacy |
-0.4023713 |
-7.0 |
| Pennsylvania |
Retail_Recreation |
-0.4001715 |
-45.0 |
| New Jersey |
Transit |
-0.4001567 |
-50.5 |
| New Mexico |
Parks |
0.3828741 |
-31.5 |
| New Hampshire |
Residential |
-0.3828116 |
14.0 |
| New Mexico |
Retail_Recreation |
-0.3783281 |
-42.5 |
| Montana |
Parks |
-0.3765165 |
-58.0 |
| Alabama |
Workplace |
-0.3674324 |
-29.0 |
| New York |
Transit |
-0.3641953 |
-48.0 |
| Hawaii |
Residential |
0.3580545 |
19.0 |
| Wisconsin |
Transit |
-0.3534841 |
-23.5 |
| Florida |
Residential |
0.3519461 |
14.0 |
| Montana |
Residential |
0.3505699 |
14.0 |
| Montana |
Transit |
0.3472663 |
-41.0 |
| Nevada |
Workplace |
-0.3472037 |
-40.0 |
| Alabama |
Grocery_Pharmacy |
-0.3457523 |
-2.0 |
| Oregon |
Parks |
-0.3456409 |
16.5 |
| Michigan |
Parks |
0.3437456 |
28.5 |
| Nebraska |
Grocery_Pharmacy |
0.3431356 |
-0.5 |
| Virginia |
Transit |
-0.3329746 |
-32.5 |
| Maryland |
Retail_Recreation |
-0.3289390 |
-39.0 |
| Maine |
Retail_Recreation |
-0.3288448 |
-42.0 |
| Nevada |
Residential |
0.3253393 |
17.0 |
| South Carolina |
Workplace |
0.3240706 |
-30.0 |
| Alaska |
Retail_Recreation |
0.3224827 |
-39.0 |
| Colorado |
Residential |
0.3222051 |
14.0 |
| North Dakota |
Workplace |
0.3091853 |
-40.0 |
| California |
Parks |
-0.3072642 |
-38.5 |
| Arkansas |
Retail_Recreation |
-0.3041952 |
-30.0 |
| Vermont |
Workplace |
-0.2994840 |
-43.0 |
| California |
Residential |
0.2988130 |
14.0 |
| Illinois |
Workplace |
-0.2985793 |
-30.5 |
| Pennsylvania |
Parks |
0.2846186 |
12.0 |
| Nevada |
Retail_Recreation |
-0.2839649 |
-43.0 |
| Minnesota |
Transit |
-0.2811077 |
-28.5 |
| Idaho |
Workplace |
-0.2788331 |
-29.0 |
| Vermont |
Retail_Recreation |
0.2783981 |
-57.0 |
| California |
Transit |
-0.2767102 |
-42.0 |
| West Virginia |
Grocery_Pharmacy |
-0.2752521 |
-6.0 |
| Pennsylvania |
Grocery_Pharmacy |
-0.2707694 |
-6.0 |
| Missouri |
Workplace |
0.2707440 |
-29.0 |
| Kansas |
Workplace |
0.2703750 |
-32.5 |
| Maryland |
Residential |
0.2669150 |
15.0 |
| Rhode Island |
Grocery_Pharmacy |
0.2621455 |
-7.5 |
| Idaho |
Transit |
-0.2596099 |
-30.0 |
| North Carolina |
Grocery_Pharmacy |
0.2567758 |
0.0 |
| North Carolina |
Workplace |
0.2561866 |
-31.0 |
| Idaho |
Grocery_Pharmacy |
-0.2554313 |
-5.5 |
| Washington |
Grocery_Pharmacy |
0.2528150 |
-7.0 |
| Tennessee |
Parks |
-0.2514103 |
10.5 |
| West Virginia |
Workplace |
0.2499720 |
-33.0 |
| Tennessee |
Workplace |
-0.2460965 |
-31.0 |
| Rhode Island |
Transit |
-0.2460045 |
-56.0 |
| Illinois |
Parks |
0.2457531 |
26.5 |
| Minnesota |
Parks |
0.2456429 |
-9.0 |
| Alabama |
Transit |
-0.2449807 |
-36.5 |
| Alabama |
Parks |
0.2444336 |
-1.0 |
| South Dakota |
Workplace |
0.2427141 |
-35.0 |
| Georgia |
Grocery_Pharmacy |
-0.2417446 |
-10.0 |
| Wisconsin |
Parks |
0.2409644 |
51.5 |
| Tennessee |
Residential |
0.2377122 |
11.5 |
| Florida |
Parks |
-0.2355734 |
-43.0 |
| Oregon |
Residential |
-0.2310860 |
10.5 |
| Missouri |
Parks |
0.2281155 |
0.0 |
| Indiana |
Parks |
-0.2273583 |
29.0 |
| New York |
Grocery_Pharmacy |
-0.2264106 |
8.0 |
| Nebraska |
Transit |
-0.2234621 |
-9.0 |
| Georgia |
Retail_Recreation |
-0.2175143 |
-41.0 |
| Idaho |
Parks |
0.2124153 |
-19.0 |
| Wyoming |
Grocery_Pharmacy |
-0.2114884 |
-10.0 |
| Georgia |
Workplace |
-0.2088598 |
-33.5 |
| Arizona |
Parks |
-0.2077651 |
-44.5 |
| Oregon |
Transit |
0.2073982 |
-27.5 |
| Texas |
Workplace |
0.2073343 |
-32.0 |
| North Dakota |
Grocery_Pharmacy |
-0.2050117 |
-8.0 |
| Connecticut |
Parks |
0.2048228 |
43.0 |
| Illinois |
Residential |
0.2016834 |
14.0 |
| South Dakota |
Residential |
0.1945860 |
15.0 |
| North Carolina |
Transit |
0.1934118 |
-32.0 |
| Kansas |
Grocery_Pharmacy |
-0.1931308 |
-14.5 |
| Colorado |
Parks |
-0.1873236 |
2.0 |
| Virginia |
Residential |
0.1865800 |
14.0 |
| Wyoming |
Workplace |
-0.1850065 |
-31.0 |
| Wisconsin |
Residential |
-0.1810737 |
14.0 |
| Mississippi |
Grocery_Pharmacy |
-0.1797100 |
-8.0 |
| New Hampshire |
Retail_Recreation |
-0.1779615 |
-41.0 |
| Oklahoma |
Parks |
0.1775129 |
-18.5 |
| Pennsylvania |
Transit |
-0.1767528 |
-42.0 |
| Texas |
Residential |
-0.1760042 |
15.0 |
| Oregon |
Retail_Recreation |
0.1738406 |
-40.5 |
| Oregon |
Grocery_Pharmacy |
-0.1715383 |
-7.0 |
| North Carolina |
Residential |
0.1713397 |
13.0 |
| Ohio |
Transit |
0.1693449 |
-28.0 |
| Indiana |
Residential |
0.1677119 |
12.0 |
| Massachusetts |
Parks |
0.1624120 |
39.0 |
| Kentucky |
Residential |
0.1594478 |
12.0 |
| Kentucky |
Grocery_Pharmacy |
0.1583371 |
4.0 |
| Kentucky |
Transit |
-0.1579524 |
-31.0 |
| Utah |
Retail_Recreation |
-0.1578711 |
-40.0 |
| Florida |
Transit |
-0.1537387 |
-49.0 |
| North Dakota |
Residential |
-0.1533154 |
17.0 |
| Montana |
Retail_Recreation |
0.1524484 |
-51.0 |
| Mississippi |
Residential |
0.1516953 |
13.0 |
| Oklahoma |
Residential |
-0.1445414 |
15.0 |
| South Carolina |
Transit |
-0.1422373 |
-45.0 |
| New Mexico |
Transit |
0.1414688 |
-38.5 |
| Mississippi |
Parks |
-0.1369984 |
-25.0 |
| New Jersey |
Residential |
0.1362882 |
18.0 |
| West Virginia |
Residential |
-0.1336602 |
11.0 |
| Minnesota |
Retail_Recreation |
0.1320453 |
-40.5 |
| Utah |
Grocery_Pharmacy |
0.1311923 |
-4.0 |
| Wisconsin |
Grocery_Pharmacy |
0.1277613 |
-1.0 |
| North Carolina |
Retail_Recreation |
0.1270227 |
-34.0 |
| Iowa |
Transit |
0.1263650 |
-24.0 |
| Virginia |
Grocery_Pharmacy |
-0.1260133 |
-8.0 |
| North Dakota |
Transit |
0.1245057 |
-48.0 |
| Mississippi |
Retail_Recreation |
-0.1219259 |
-40.0 |
| Kansas |
Transit |
-0.1216098 |
-23.0 |
| Indiana |
Retail_Recreation |
0.1204022 |
-38.0 |
| Kansas |
Parks |
0.1198176 |
72.0 |
| Texas |
Parks |
0.1195841 |
-42.0 |
| Vermont |
Transit |
-0.1163582 |
-63.0 |
| Texas |
Grocery_Pharmacy |
0.1152372 |
-14.0 |
| Michigan |
Workplace |
-0.1121000 |
-40.0 |
| Idaho |
Retail_Recreation |
-0.1115842 |
-40.0 |
| Wisconsin |
Workplace |
-0.1107145 |
-31.0 |
| New Hampshire |
Grocery_Pharmacy |
-0.1101549 |
-6.0 |
| Oklahoma |
Grocery_Pharmacy |
-0.1073430 |
-0.5 |
| Nebraska |
Retail_Recreation |
0.1067249 |
-36.0 |
| Iowa |
Grocery_Pharmacy |
-0.1037112 |
4.0 |
| Oklahoma |
Workplace |
0.1028192 |
-31.0 |
| Minnesota |
Grocery_Pharmacy |
0.1001441 |
-6.0 |
| Virginia |
Parks |
0.0990233 |
6.0 |
| Alabama |
Retail_Recreation |
0.0989716 |
-39.0 |
| Missouri |
Transit |
-0.0988464 |
-24.5 |
| Massachusetts |
Residential |
0.0983701 |
15.0 |
| Massachusetts |
Transit |
-0.0983541 |
-45.0 |
| Iowa |
Workplace |
0.0966075 |
-30.0 |
| Maryland |
Transit |
-0.0955336 |
-39.0 |
| Indiana |
Workplace |
0.0951220 |
-34.0 |
| Arkansas |
Workplace |
-0.0907779 |
-26.0 |
| California |
Grocery_Pharmacy |
-0.0905986 |
-11.5 |
| Alabama |
Residential |
-0.0900233 |
11.0 |
| Arkansas |
Transit |
-0.0900018 |
-27.0 |
| Wyoming |
Transit |
-0.0897314 |
-17.0 |
| New York |
Residential |
0.0888871 |
17.5 |
| Georgia |
Transit |
-0.0883979 |
-35.0 |
| Arkansas |
Residential |
-0.0861542 |
12.0 |
| Michigan |
Transit |
0.0843991 |
-46.0 |
| Montana |
Workplace |
-0.0829065 |
-40.0 |
| California |
Retail_Recreation |
-0.0786922 |
-44.0 |
| Virginia |
Retail_Recreation |
-0.0779604 |
-35.0 |
| Washington |
Retail_Recreation |
0.0740991 |
-42.0 |
| West Virginia |
Retail_Recreation |
-0.0720076 |
-38.5 |
| Ohio |
Grocery_Pharmacy |
0.0710103 |
0.0 |
| Oregon |
Workplace |
0.0703615 |
-31.0 |
| Kentucky |
Retail_Recreation |
0.0692770 |
-29.0 |
| Ohio |
Residential |
0.0689441 |
14.0 |
| Pennsylvania |
Residential |
0.0680125 |
15.0 |
| West Virginia |
Transit |
-0.0668808 |
-45.0 |
| South Carolina |
Residential |
-0.0635251 |
12.0 |
| Michigan |
Retail_Recreation |
-0.0619322 |
-53.0 |
| South Dakota |
Transit |
-0.0605721 |
-40.0 |
| Florida |
Retail_Recreation |
0.0600155 |
-43.0 |
| Virginia |
Workplace |
-0.0590807 |
-32.0 |
| Minnesota |
Residential |
-0.0579750 |
17.0 |
| Tennessee |
Transit |
0.0572473 |
-32.0 |
| Iowa |
Retail_Recreation |
0.0571980 |
-38.0 |
| North Carolina |
Parks |
-0.0564212 |
7.0 |
| South Dakota |
Retail_Recreation |
-0.0562015 |
-39.0 |
| Michigan |
Residential |
0.0558708 |
15.0 |
| New Hampshire |
Transit |
0.0557898 |
-57.0 |
| Washington |
Transit |
-0.0545249 |
-33.5 |
| South Carolina |
Grocery_Pharmacy |
-0.0542759 |
1.0 |
| Georgia |
Parks |
0.0539916 |
-6.0 |
| Texas |
Retail_Recreation |
0.0533583 |
-40.0 |
| Indiana |
Transit |
0.0517161 |
-29.0 |
| Arkansas |
Grocery_Pharmacy |
-0.0514819 |
3.0 |
| New Mexico |
Workplace |
0.0458555 |
-34.0 |
| Mississippi |
Workplace |
0.0456589 |
-33.0 |
| Colorado |
Retail_Recreation |
-0.0447725 |
-44.0 |
| Ohio |
Workplace |
-0.0439973 |
-35.0 |
| Florida |
Workplace |
0.0427143 |
-33.0 |
| Arizona |
Workplace |
-0.0424958 |
-35.0 |
| Illinois |
Retail_Recreation |
0.0415781 |
-40.0 |
| New Hampshire |
Workplace |
0.0364884 |
-37.0 |
| Missouri |
Grocery_Pharmacy |
-0.0361160 |
2.0 |
| Ohio |
Retail_Recreation |
0.0353986 |
-36.0 |
| Tennessee |
Retail_Recreation |
-0.0347219 |
-30.0 |
| Wyoming |
Retail_Recreation |
0.0343831 |
-39.0 |
| Washington |
Workplace |
0.0339872 |
-38.0 |
| Kentucky |
Workplace |
-0.0324807 |
-36.5 |
| Nebraska |
Parks |
0.0314042 |
55.5 |
| Colorado |
Grocery_Pharmacy |
-0.0313079 |
-17.0 |
| Wyoming |
Residential |
0.0305690 |
12.5 |
| Mississippi |
Transit |
0.0302557 |
-38.5 |
| Texas |
Transit |
0.0300339 |
-41.5 |
| Oklahoma |
Retail_Recreation |
-0.0296660 |
-31.0 |
| Nevada |
Parks |
0.0281423 |
-12.5 |
| Maine |
Residential |
-0.0262934 |
11.0 |
| Washington |
Residential |
-0.0249645 |
13.0 |
| Maine |
Grocery_Pharmacy |
-0.0244000 |
-13.0 |
| Iowa |
Residential |
0.0236516 |
13.0 |
| Georgia |
Residential |
-0.0231487 |
13.0 |
| Oklahoma |
Transit |
0.0206542 |
-26.0 |
| Missouri |
Retail_Recreation |
-0.0203047 |
-36.0 |
| Illinois |
Grocery_Pharmacy |
-0.0195896 |
2.0 |
| California |
Workplace |
0.0191664 |
-36.0 |
| Colorado |
Transit |
0.0186400 |
-36.0 |
| Montana |
Grocery_Pharmacy |
0.0172809 |
-16.0 |
| South Dakota |
Grocery_Pharmacy |
-0.0167764 |
-9.0 |
| Kansas |
Residential |
-0.0156304 |
13.0 |
| Maryland |
Parks |
0.0152397 |
27.0 |
| Florida |
Grocery_Pharmacy |
-0.0148329 |
-14.0 |
| Michigan |
Grocery_Pharmacy |
0.0145288 |
-11.0 |
| South Carolina |
Retail_Recreation |
-0.0128589 |
-35.0 |
| Minnesota |
Workplace |
-0.0110191 |
-33.0 |
| Tennessee |
Grocery_Pharmacy |
0.0060957 |
6.0 |
| Ohio |
Parks |
-0.0058202 |
67.5 |
| Nevada |
Grocery_Pharmacy |
-0.0050303 |
-12.5 |
| Washington |
Parks |
-0.0048955 |
-3.5 |
| Wisconsin |
Retail_Recreation |
-0.0040934 |
-44.0 |
| Kansas |
Retail_Recreation |
0.0030842 |
-38.0 |
| Indiana |
Grocery_Pharmacy |
0.0030371 |
-5.5 |
| Colorado |
Workplace |
-0.0014878 |
-39.0 |
| Alaska |
Parks |
NA |
29.0 |
| District of Columbia |
Retail_Recreation |
NA |
-69.0 |
| District of Columbia |
Grocery_Pharmacy |
NA |
-28.0 |
| District of Columbia |
Parks |
NA |
-65.0 |
| District of Columbia |
Transit |
NA |
-69.0 |
| District of Columbia |
Workplace |
NA |
-48.0 |
| District of Columbia |
Residential |
NA |
17.0 |
# sanity check
ggplot(filter(plot_data,Province.State %in% c("Pennsylvania","Maryland","New Jersey","California","Delaware","Connecticut")),aes(x=Total_confirmed_cases.per100,fill=variable))+geom_histogram()+
facet_grid(~Province.State)+
default_theme+
theme(legend.position = "bottom")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

write_plot(mobility.plot,wd = results_dir)
## [1] "/Users/stevensmith/Projects/coronavirus/results/mobility.plot.png"
write_plot(mobility.global.plot,wd = results_dir)
## [1] "/Users/stevensmith/Projects/coronavirus/results/mobility.global.plot.png"
(plot_data.permobility_summary.plot<-ggplot(plot_data.permobility_summary,aes(x=variable,y=median_change))+
geom_jitter(size=2,width=.2)+
#geom_jitter(data=plot_data.permobility_summary %>% arrange(-abs(median_change)) %>% head(n=15),aes(col=Province.State),size=2,width=.2)+
default_theme+
ggtitle("Per-Sate Median Change in Mobility")+
xlab("Mobility Meaure")+
ylab("Median Change from Baseline"))

write_plot(plot_data.permobility_summary.plot,wd = results_dir)
## [1] "/Users/stevensmith/Projects/coronavirus/results/plot_data.permobility_summary.plot.png"